<?php
namespace Admin\Controller;
use Think\Controller;
class LogisticsController extends BaseController {
    public function index(){
     $this->display();


    }

    
    //物流查询
  public   function logistics_query(){
            //物流单号
            $code = I('request.code','','trim'); 

            if(empty($code)){
           echo json_encode(array('status'=>0,'info'=>'物流单号为空'));
            exit;            
            }
            $dbprefix=C('DB_PREFIX');
            $list= M("order_info")->field("o.order_id AS orderid,o.order_sn AS ordercode,o.org_order_sn AS org_ordercode,c.name AS companyname,b.`group_name`,c.weburl,b.`configurl`,d.invoice_no AS invoicecode,FROM_UNIXTIME(d.`add_time`,'%Y-%m-%d %H:%i:%s') AS add_time")
            ->alias("o")->join(" inner join ".$dbprefix."delivery_order d ON o.order_id=d.order_id")
            ->join(" inner join ".$dbprefix."expresscompany c ON c.id= d.expresscompany_id")
            ->join(" inner join ".$dbprefix."expresscompany_group b ON c.exp_gronp_id=b.id")->where("d.invoice_no='$code'")->select(); 
           
            if(!$list || count($list)==0){  
            echo json_encode(array('status'=>0,'info'=>'请确认是否已经发送物流货运'));
            exit; 
            }  
           //$str="";
            foreach ($list as $k=>$v){
                //原始订单号，订单号，物流公司，物流号，发货时间，物流公司查询地址。
                $temp= $v['configurl']?str_replace("{code}", $v['invoicecode'], $v['configurl']):"http://".$v['weburl'];
                //$str = $str.((empty($str)?"":",")."{\"org_ordercode\":\"".$v['org_ordercode']."\",\"ordercode\":\"".$v['ordercode']."\",\"companyname\":\"".$v['group_name']."-".$v['companyname']."\",\"invoicecode\":\"".$v['invoicecode']."\",\"time\":\"".$v['add_time']."\",\"url\":\"".$temp."\"}");
            } 
            //print_r($temp);

           echo json_encode(array('status'=>1,'info'=>$temp));
            exit;
    }





}